***** Replication of the analytical code for "When Audience Segmentation is Twofold: Differences in Media Consumption along Race and Socio-Economic Background at a South African University. *****

	// By David Schieferdecker.
	// This version: 6th of April 2017.
	// This Stata do-file allows to replicate the analysis presented in the article. 
	// This Stata do-file is complemented by a Mplus input file that document the implementation of the latent class analysis.
	// This analysis works with data from the survey "Media Usage, Attitudes on Race and Intergroup Contact", implemented by David Schieferdecker in 2014 at a South African university.
	
	// This analysis uses the data set "whensegmentationistwofold-main.dta". In the data set, variables from the original survey data set are merged with results of the final solution of the latent class analysis (which can be reproduced using the Mplus input file and the data set "whensegmentationistwofold-lca.dta"). I only kept those variables in the data set that are necessary for the analytical steps refered to in the article. The number of observations differs between "whensegmentationistwofold-lca.dta" and "whensegmentationistwofold-main.dta". This results from the fact that I excluded respondents from all analyses, but the exploration of the usage patterns, (a) who did not identify as Black- or White South African, (b) who had not lived in South Africa for more than 7 years, (c) who have not been assigned a usage pattern due to non-response on all consumption variables.
	
*** Set-up of variables (quasi-codebook)
		clear all
		cd "..." // Please change to your working directory.
		use "whensegmentationistwofold-main.dta"		
		label var icind "Outgroup contact" // (Index, 0-10)
		label var v10 "Household income" // (1-4)
		label var v10s "Household income split" // (1,2)
		label var v8bidi "Being Black (vs. White)" // (0,1)
		label var v5bins "Having attended a (semi-)private school (vs. a public school)" // (1, 2)
		label var v7g "Being male (vs. female)" // (1,2)
		label var v3d "Year of study" // (1, 2, 3, 4, 5, 5.5, 7.5)
		label var v6 "Age" // (18-73)
		label var v1112b "Being able to understand an African language" // (0,1)
		label var v13a "Generations, Muvhango, Rhythm City, Isibaya, Scandal! (on e.TV), Zabalaza, Soul City" // (1-5)
		label var v13b "7de Laan, Binnelanders" // (1-5)
		label var v13c "Isidingo" // (1-5)
		label var v14a "SABC1" // (1-5)
		label var v14b "SABC2" // (1-5)
		label var v14c "SABC3" // (1-5)
		label var v14d "e.tv" // (1-5)
		label var v14e "M-Net (including M-Net series, movies, etc.)" // (1-5)
		label var v14f "Mzansi (including Mzansi Magic, Wethu, Bioskop, Music)" // (1-5)
		label var v14g "Vuzu" // (1-5)
		label var v14h "Supersport 4" // (1-5)
		label var v14i "Supersport 1" // (1-5)
		label var v14j "KykNET" // (1-5)
		label var v15a "Umhlobo Wenene, Lesedi FM, Ukhozi FM, Motsweding FM" // (1-5)
		label var v15b "Metro FM, Y FM, Tru FM, Power FM" // (1-5)
		label var v15c "Algoa, RSG" // (1-5)
		label var v15d "5 FM, East Coast Radio, K FM, Highveld Stereo" // (1-5)
		label var v15e "Radio 2000, SA FM, Talkradio 702, 567 Cape Talk" // (1-5)
		label var v16a "Drum, TrueLove, Bona, Destiny, Move!" // (1-5)
		label var v16b "Seventeen, You, Huisgenoot" // (1-5)
		label var v16c "Mail and Guardian, Times/Sunday Times/TimesLIVE, Daily Dispatch/DispatchLIVE, Herald/HeraldLIVE, Weekend Post" // (1-5)
		label var v16d "City Press, Sowetan/SowetanLIVE" // (1-5)
		label var v16e "IOL, News24" // (1-5)
		label var v16f "Beeld, Die Burger, Rapport" // (1-5)
		label var v16g "Daily Sun/Sunday Sun" // (1-5)
		label var v16j "Grocotts Mail, Oppidan Press, Activate" // (1-5)
		label var v16h "Kickoff, Soccer Laduma" // (1-5)
		label var v16i "Sa Rugby, Zig Zag" // (1-5)
		label var v17 "Lenght of daily social media usage" // (1-4)
		label var v18 "Being a weak user of social media usage" // (0,1)
		label var C "Usage patterns as provided by LCA" 
			label def pattern0 1 "Power users with South African orientation" 2"Weak users with a South African orientation" 3"All-rounder" 4"Power users with a global orientation" 5 "Weak users with a global orientation" 6 "News focus" 
					lab val C pattern0
		label var CCCC "Usage patterns grouped for regression" // This is a recoded version of C that merges the patterns of the two major orientation (C1 & C2 = CCCC1, C4&C5 = CCCC2).
				label def patterns2 1 "Users with South African orientation" 2 "Users with global orientation" 3 "Allrounders" 4 "News focus"
					label val CCCC patterns2
		label var raceses "Combination of race and socio-economic status (Income and Schooling)"
			label def raceses 1 "Black, lower income and public school" 2 "Black, lower income and (semi-)private school" 3 "White, lower income and (semi-)private school" 4 "Black, higher income and (semi-)private school" 5 "White, higher income and (semi-)private school" // The remaining possible combinations were turned to missing as the group sizes were very small.
		save "whensegmentationistwofold-main.dta", replace 			
				
*** Figure 1: Medians of the consumption of outlets in one item in the last six months by group
	// I compute medians for all media usage variables for the different group combinations of race and socio-economic background.
		keep lfdn raceses v13a v13b v13c v14a v14b v14c v14d v14e v14f v14g v14h v14i v14j v15a v15b v15c v15d v15e v16a v16b v16c v16d v16e v16f v16g v16j v16h v16i
		collapse (median) v13a v13b v13c v14a v14b v14c v14d v14e v14f v14g v14h v14i v14j v15a v15b v15c v15d v15e v16a v16b v16c v16d v16e v16f v16g v16j v16h v16i, by(raceses)
		drop if raceses==.
		edit
	// I copied this data set to MS Excel and manually produced the bar charts.

	
*** Figure 2: Media usage patterns
	// Mplus produces the estimated probabilities to use outlets in one item for each class regularly. I copied this data into MS Excel and manually produced the bar charts.
	
	
*** Uni- and bivariate statistics in order of appearance
	clear all
	cd "..." 
	use "whensegmentationistwofold-main.dta"
	tab v17
	tab v18
	tab CCCC v8bidi, row
	tab CCCC v5bins, row
	tab CCCC v10s, row
	bys v8bidi: sum icind
	
	
*** Regression 
	// I run a multinomial logistic regression. I run a base model without an interaction between direct outgroup contact and race, and a second model that includes the interaction.
	// I compute Average Margin Effects for both models and, subsequently, for the interaction.
		clear all
		cd "..." 
		use "whensegmentationistwofold-main.dta"
		qui mlogit CCCC i.v8bidi v10 i.v5bins icind i.v1112b i.v7g v3d v6, rrr base(1)
			margins, dydx(*) post
			eststo mlogit1
		qui mlogit CCCC i.v8bidi v10 i.v5bins icind c.icind#i.v8bidi i.v1112b i.v7g v3d v6, rrr base(1)
			margins, dydx(*) post
			eststo mlogit2
			esttab mlogit1 mlogit2, b(2) // This comparison shows that the differences in Average Margin Effects between the base- and the interaction model are negligible (as stated in the note to Table 1).
		qui mlogit CCCC i.v8bidi v10 i.v5bins icind c.icind#i.v8bidi i.v1112b i.v7g v3d v6, rrr base(1)
			margins, dydx(icind) at (v8bidi=(0 1))
	// I export a table with the base model.
		clear all
		cd "..."
		use "whensegmentationistwofold-main.dta"
		qui mlogit CCCC i.v8bidi v10 i.v5bins icind i.v1112b i.v7g v3d v6, rrr base(1)
			eststo mlogit
			foreach o in 1 2 3 4 {
				quietly margins, dydx(*) predict(outcome(`o')) post
				eststo, title(Outcome `o')
				estimates restore mlogit
				}
			eststo drop mlogit
			# delimit ;
			esttab using "Table",
				title(Average Marginal Effects) 
				mtitles("To be South African-oriented" "To be globally-oriented" "To be an all-rounder" "To have a news focus") 
				star(* 0.05) 
				nonumbers 
				label 
				nobaselevels 
				not
				b(2)
				obslast
				coeflabels(v8bidi "Being Black" icind "Direct outgroup contact" v10 "Household Income" v5bins "Having attended a (semi-)private school" v7g "Being male" v3 "Year of study" v112b "Being able to understand an African language" v6 "Age")
				rtf
				replace
				;
			# delimit cr;
		// I manually added the rows containing the interaction effects to Table 1 and formatted it in MS Word.

